package com.fy.sys.controller;

import com.fy.core.vo.ApiRest;
import com.fy.sys.entity.Dept;
import com.fy.sys.entity.DictData;
import com.fy.sys.entity.DictType;
import com.fy.sys.service.DictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author hxd
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/dictData")
@CrossOrigin
public class DictDataController {

    @Autowired
    private DictDataService dictDataService;

    @PostMapping("/findAll")
    public ApiRest<List<DictData>> findAll(String dictType){
        return  ApiRest.success(dictDataService.findAll(dictType));
    }


    @PostMapping("/addDictData")
    public ApiRest addDictData(@RequestBody DictData dictData){
        dictDataService.add(dictData);
        return ApiRest.success("添加成功","");
    }


    @PostMapping(value = "/updateDictData")
    public ApiRest<Object> updateDictData(@RequestBody DictData dictData) {

        dictDataService.updateById(dictData);
        return ApiRest.success("deleted successfully","");
    }

    @PostMapping(value = "/updateDictDataAndStatus")
    public ApiRest<Object> updateDictDataAndStatus( Long dictCode) {
        dictDataService.updateByStatus(dictCode);

        return ApiRest.success("updateStatus successfully","");
    }

    @PostMapping(value = "/deleteDictData")
    public ApiRest<Object> deleteDictData(Long dictCode) {
        dictDataService.deleteDictData(dictCode);
        return ApiRest.success("deleted successfully","");
    }

    @PostMapping(value = "/batchDelete")
    public ApiRest<Object> batchDelete(@RequestBody List<DictData> dictDatas){
        dictDataService.batchDelete(dictDatas);
        return ApiRest.success("batchDelete successfully","");
    }
}
